const ctx = document.getElementById('myChart').getContext('2d');
let myChart = null;

const data = {
    labels: ['数学', '物理', '化学', '生物', '历史', '地理'],
    datasets: [{
        label: '学生选课',
        data: [40, 20, 12, 39, 10, 40],
        backgroundColor: 'rgba(75, 192, 192, 0.2)',
        borderColor: 'rgba(75, 192, 192, 1)',
        borderWidth: 1
    }, {
        label: '教师选课',
        data: [20, 30, 15, 25, 30, 10],
        backgroundColor: 'rgba(153, 102, 255, 0.2)',
        borderColor: 'rgba(153, 102, 255, 1)',
        borderWidth: 1
    }]
};

const options = {
    responsive: true,
    plugins: {
        legend: {
            position: 'top'
        }
    }
};

function setChartType(type) {
    if (myChart) {
        myChart.destroy();
    }
    myChart = new Chart(ctx, {
        type: type,
        data: data,
        options: options
    });
}

// 默认设置为折线图
setChartType('line');

